#include <pthread.h>
#include <stdio.h>
#include <semaphore.h>
#define MAX 100
sem_t sem1, sem2;
int global = 1;
void *t1_exe(void *arg)
{
    while (global < MAX)
    {
        sem_wait(&sem1);
        printf("Thread1: %d\n", global++);
        sem_post(&sem2);
    }
}
void *t2_exe(void *arg)
{
    while (global < MAX)
    {
        sem_wait(&sem2);
        printf("Thread2: %d\n", global++);
        sem_post(&sem1);
    }
}
void main()
{
    sem_init(&sem1, 0, 1);
    sem_init(&sem2, 0, 0);
    pthread_t pid1, pid2;
    pthread_create(&pid1, NULL, t1_exe, NULL);
    pthread_create(&pid2, NULL, t2_exe, NULL);
    pthread_join(pid1, NULL);
    pthread_join(pid2, NULL);
}